#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: api16_custom_node.py 
@version:
@time: 2022/05/25 
"""
from TapClientCore.T02_tm_api.v2_api.v2_api_base import *


class Api16CustomNodeUrl(V2ApiUrlBase):
    url_custom_node = api_joint(V2ApiUrlBase().server, 'customNode')


class Api16CustomNode(V2ApiBase, Api16CustomNodeUrl):

    def get_custom_node_by_filter(self, filter):
        response = self.tapclient(
            self.get,
            self.url_custom_node
            + self.access_token
            + self.filter(filter)
        )
        return response

    def post_custom_node(self, payload):
        response = self.tapclient(
            self.post,
            self.url_custom_node
            + self.access_token,
            json=payload
        )
        return response

    # patch need id:
    def patch_custom_node(self, payload):
        response = self.tapclient(
            self.patch,
            self.url_custom_node
            + self.access_token,
            json=payload
        )
        return response

    def delete_custom_node_by_id(self, id):
        response = self.tapclient(
            self.delete,
            api_joint(self.url_custom_node, id)
            + self.access_token
        )
        return response


if __name__ == '__main__':
    T = Api16CustomNode()
    data = {"id": "628dcf3f01443e77f21fa4d4",
            "name": "robot_mobile",
            "formSchema": {"form": {"labelCol": 6, "wrapperCol": 12, "style": {"opacity": 1}},
                           "schema": {"type": "object", "properties": {
                               "masking_field_name": {"type": "string", "title": "手机字段名", "x-decorator": "FormItem",
                                                      "x-component": "Input",
                                                      "x-component-props": {"style": {"opacity": 1}},
                                                      "x-decorator-props": {"style": {"opacity": 1}},
                                                      "x-designable-id": "8cbi7ho1dzi", "x-index": 0,
                                                      "name": "masking_field_name"}},
                                      "x-designable-id": "sghp5g00kpq"}},
            "template": "function process(record, form){\n\nvar str=\"18912341234\"\nvar pat=/(\\d{3})\\d*(\\d{4})/\nvar b=str.replace(pat,'$1****$2');\nconsole.log(b);\nrecord[form.masking_field_name] =  record[form.masking_field_name].replace(\"1234\",\"****\");  \nreturn record;\n}\n"}
    T.post_custom_node(data)
    # _id = '628dcf3f01443e77f21fa4d4'
    # T.delete_custom_node_by_id(_id)
